#include<bits/stdc++.h>
using namespace std;
int t,n,m,L,V,ans,d[100002],v[100002],a[100002],p[100002];
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin>>t;
	while(t--){
		cin>>n>>m>>L>>V;
		for(int i=1;i<=n;i++)cin>>d[i]>>v[i]>>a[i];
		for(int i=1;i<=m;i++)cin>>p[i];
		for(int i=1;i<=n;i++)
			if(v[i]>V)ans++;
		cout<<ans<<" "<<m-1<<endl;
	}
	return 0;
}
